const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    target: cc.Node=null;

    @property
    speed: number = 0;

    // onLoad () {}

    trigger: number;
    start() {
        this.trigger = -this.node.width;

    }

    update(dt) { }

    bgMove(dt) {
        // 背景移动
        this.node.x -= dt * this.speed;
        this.target.x -= dt * this.speed;

        // 重置
        if (this.node.x <= this.trigger) {
            this.node.x = this.node.x + this.target.width;
        }
        else if (this.target.x <= this.trigger) {
            this.target.x = this.target.x + this.node.width;
        }
    }
}
